<?php

/**
 * Class ServiceOutletController
 */
class ServiceOutletController extends BaseController
{
    use \app\library\traits\Restful;

    /**
     * 获取单个详情
     */
    public function read()
    {
        $category_id = intval($this->getRequest()->getQuery('category_id'));
        $page = intval($this->getRequest()->getQuery('page'));
        $pagesize = intval($this->getRequest()->getQuery('pagesize'));
        $longitude = floatval($this->getRequest()->getQuery('longitude'));
        $latitude = floatval($this->getRequest()->getQuery('latitude'));
        if (empty($category_id) || empty($page) || empty($pagesize) || empty($latitude) || empty($longitude)) {
            return $this->returnError(10001, '缺少参数');
        }
        $list = (new ServiceOutletModel())->findListByCategoryOrderDistance($category_id, $page, $pagesize, $longitude, $latitude);
        if (!$list) {
            return $this->returnError(10006, '不存在');
        }

        return $this->returnSuccess([
            'list' => $list
        ]);
    }

    /**
     * 获取全部可用分类
     */
    public function getCategoryAllAction(){
        $list = (new ServiceOutletCategoryModel())->findAllOpen();
        return $this->returnSuccess($list);
    }
}
